<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>普通函数的this与箭头函数的this的区别</title>
    <style>
        div {
            height: 300px;
            width: 300px;
            text-align: center;
            background-color: lightskyblue;
            color: white;
            margin: auto;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>
<body>
<div>
    <p class="normalP"></p>
    <p class="arrowP"></p>
</div>

<script>
    const normalP = document.querySelector(".normalP")
    const arrowP = document.querySelector(".arrowP")
    let icecream = {
        name: "冰激凌",
        flavour: ["草莓味", "巧克力味"],
        adding: function () {
            this.flavour.map(function (item) {
                normalP.innerHTML += item + this.name + ";";
            }.bind(this));
        },
        adding2: function () {
            this.flavour.map(function (item) {
                normalP.innerHTML += item + this.name + ";";
            });
        },
        adding3: function () {
            this.flavour.map(item => arrowP.innerHTML += item + this.name + ";")
        }
    }

    icecream.adding();
    // icecream.adding2();

    /*箭头函数this的值就取决于外部普通函数里的this值*/
    icecream.adding3()


</script>
</body>
</html>